/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wii.elpro.dao.hb;

import com.wii.elpro.dao.HibernateUtil;
import com.wii.elpro.dao.SpdcfDAOInterface;
import com.wii.elpro.entity.Spdcf;
import com.wii.elpro.entity.User;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author hendro
 */
public class SpdcfDAOImpl extends DAOGenericImpl implements SpdcfDAOInterface{

    public Spdcf getSpdcf(long id) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return (Spdcf)session.load(Spdcf.class, id);
        }catch(Exception ex){
            throw ex;
        }
    }

    public List<Spdcf> getSpdcf() throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return session.createQuery("SELECT s FROM Spdcf s").list();
        }catch(Exception ex){
            throw ex;
        }
    }

    public List<Spdcf> getSpdcfBySales(User sales) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return session.createQuery("SELECT s FROM Spdcf s WHERE s.inquery.sales=:input")
                    .setParameter("input", sales).list();
        }catch(Exception ex){
            throw ex;
        }
    }

    public List<Spdcf> getSpdcfThatConfirmByProduksiAndNotYetConfirmByFinance(User sales) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return session.createQuery("SELECT s FROM Spdcf s WHERE s.inquery.sales=:input AND s.wasKonfirmByProduction=:input1 AND s.wasKonfirmByFinance=:input2")
                    .setParameter("input", sales)
                    .setParameter("input1", 1)
                    .setParameter("input2", 0).list();
        }catch(Exception ex){
            throw ex;
        }
    }

    public List<Spdcf> getSpdcfThatNotYetConfirmByProduksi(User sales,int confirm) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return session.createQuery("SELECT s FROM Spdcf s WHERE s.inquery.sales=:input AND s.wasKonfirmByProduction=:input1 AND s.wasKonfirmByFinance=:input2")
                    .setParameter("input", sales)
                    .setParameter("input1", 0)
                    .setParameter("input2", 0).list();
        }catch(Exception ex){
            throw ex;
        }
    }

    public List<Spdcf> getSpdcfThatConfirmBoth(User sales) throws Exception {
         HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try{
            return session.createQuery("SELECT s FROM Spdcf s WHERE s.inquery.sales=:input AND s.wasKonfirmByProduction=:input1 AND s.wasKonfirmByFinance=:input2")
                    .setParameter("input", sales)
                    .setParameter("input1", 1)
                    .setParameter("input2", 1).list();
        }catch(Exception ex){
            throw ex;
        }
    }

}
